package com.zlj.jdbc.transcation;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class AccountDao {
	/**
	 *  修改指定用户的余额
	 * @param conn
	 * @param name
	 * @param money
	 */
    public void updateBalance(Connection conn, String name, double balance) {
    	PreparedStatement statement = null;
		try {
			//给出sql模板
			String sql = "update account set balance = balance + ? where name = ?";
			//创建statement
			statement = conn.prepareStatement(sql );
			//对参数进行赋值
			statement.setDouble(1, balance);
			statement.setString(2, name);
			//执行
			statement.executeUpdate();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
    }
}
